$(document).ready(function(){
	
	getCurrent(1,10);

	$('#firstPage').click(function(){		
		var page=1;
		var maxRow=$("#maxRow").text();
		getCurrent(page,maxRow);
	});
	
	$('#prePage').click(function(){		
		var page=$("#page").text();
		page=(parseInt(page)-1);
		var maxRow=$("#maxRow").text();
		if(page<=0){
			alert("第一页了");
			return ;
		}
		getCurrent(page,maxRow);
	});
	
	$('#nextPage').click(function(){		
		var page=$("#page").text();
		page=(parseInt(page)+1);
		var maxRow=$("#maxRow").text();
		var pageCount=$("#pageCount").text();
		if(page>=pageCount){
			alert("最后一页了");
			return;
		}
		getCurrent(page,maxRow);
	});
	
	$('#lastPage').click(function(){		
		var page=$("#pageCount").text();
		var maxRow=$("#maxRow").text();
		getCurrent(page,maxRow);
	});
	
	$('#jumpPage').click(function(){		
		var pageCount=$("#pageCount").text();
		var maxRow=$("#maxRow").text();
		var page=$("#jump").val();
		if(page>pageCount){
			alert("页数过大");
			return;
		}
		getCurrent(page,maxRow);
	});

});

function getCurrent(page1,maxRow1){
		var page=page1;
		var maxRow=maxRow1;
		var typeID=$(window.parent.frames["topFrame"].document).find('#typeID  option:selected').val();
		var expName=$(window.parent.frames["topFrame"].document).find('#expNameID').val();
		var areaID=$(window.parent.frames["topFrame"].document).find('#areaID  option:selected').val();
		//var expRusume=$(window.parent.frames["topFrame"].document).find('#expRusumeID').val();
		
		$('#expertBody').empty();
		$("#loadingPerson").show();
		$.ajax({
  			type: "post",
 			url: "hmk/findSomeExpert_findExpertList.action",
 			data:{
 				  typeID1:typeID,areaID1:areaID,expName1:expName,
 				  page:page,maxRow:maxRow
 				 },
  			success:showData
		});
}

	function getExpertDetail(v){
		var content = $(v).next().text();
		window.location.href="/ag/hmk/findOneExpert_findOneExpert.action?expertID="+content+"&findType1=1";	
	}

	//删除专家
	function delExpert(v){
		var isPass = confirm("确定要删除吗？");
		if(isPass){
			var content = $(v).next().text();
			$.ajax({
  				type: "post",
 				url: "hmk/delExpert_delExpert.action",
 				data:{
 				  expertID:content
 				 },
  				success:delData
			});
		}
		
	}

	function delData(data){
		if(data.ajaxRST=='1'){
			alert("删除成功！");
			window.location.replace("/ag/hmk/ExpertMain.jsp");
		 }else{
			alert("删除失败！");
		 }
	}
	
	function showData(data){
		$('#expertBody').empty();	
		if(data.pageUtil.list.length==0){
			$("#loadingPerson").hide();
			$("#nonePerson").show();
			$("#total").text(0);
			$("#page").text(0);
			$("#pageCount").text(0);
			$("#maxRow").text(0);
		}else{
			$("#nonePerson").hide();
		    $("#loadingPerson").hide();
		    $.each(data.pageUtil.list,function(i,n){
				var sex ="男";
				if(n.expSex=='0') sex="女";
				//var event = data.eventList[i];
				fillDataToHtml(n.expId,n.tbType.tpyeName,n.tbExpertArea.expareaName,n.expName,
						  sex,n.expMobile,n.expUnit,n.expTitle,n.expPost,data.eventList[i]);
		  	});
		
		$('#total').text(data.pageUtil.total);
		$('#page').text(data.pageUtil.page);
		$('#pageCount').text(Math.ceil(data.pageUtil.total/10));
		$('#maxRow').text(data.pageUtil.maxRow);
		}
	}
	
	function fillDataToHtml(eid,etype,earea,ename,esex,ephone,eunit,etitle,epost,eventlist){
		// strHtml+=ebirthday.replace(/T/," ")+"</div></td>";
		var strHtml="<tr>";
		strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=etype+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=earea+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=ename+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=esex+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=ephone+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=eunit+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=etitle+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=epost+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=eventlist+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center'><img src='hmk/images/037.gif' width='9' height='9' /><span class='STYLE1'> [</span><a style='cursor:pointer' onclick='getExpertDetail(this)'>详情</a>";
        	strHtml+="<span  style='display:none'>";
	    	strHtml+=eid;
	    	strHtml+="</span>";
        strHtml+="<span class='STYLE1'>]</span></div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center'><span class='STYLE2'><img src='hmk/images/010.gif' width='9' height='9' /> </span><span class='STYLE1'>[</span><a style='cursor:pointer' onclick='delExpert(this)'>删除</a>";
        	strHtml+="<span  style='display:none'>";
	    	strHtml+=eid;
	    	strHtml+="</span>";
        strHtml+="<span class='STYLE1'>]</span></div></td>"
        strHtml+="</tr>";
        
        $('#expertBody').append(strHtml);
	}